﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Flockmaster;

namespace 数据库复制工具toSQLServer
{
    public class TableMessage
    {
        string _tablename;
        List<string> _colums=new List<string>();
        List<string> _filters=new List<string>();

        public List<string>  Colums
        {
            get { return _colums; }
            set { _colums = value; }
        }

        public List<string> Fileter
        {
            get { return _filters; }
            set { _filters = value; }
        }

        public string TableName
        {
            get { return _tablename; }
            set { _tablename = value; }
        }

        public string GetSqlCmd()
        {
            string sqlcmd = String.Empty;
            string _column = String.Empty;
            string _filter = String.Empty;
            for (int i = 0; i < _colums.Count; i++)
            {
                if (i != 0)
                {
                    _column += ",";
                }
                _column += _colums[i];
            }
            for (int j = 0; j < _filters.Count; j++)
            {
                if (j != 0)
                {
                    _filter += " and ";
                }
                _filter += _filters[j];
            }

            if (_column == String.Empty)
            {
                _column = "*";
            }
            if (_filter == String.Empty)
            {
                _filter = "";
            }
            else
            {
                _filter = "where " + _filter;
            }
            sqlcmd = string.Format("select {0} from {1} {2}", _column, _tablename, _filter);
            return sqlcmd;
        }

        public void Clear()
        {
            _colums.Clear();
            _filters.Clear();
        }
    }
    public partial class Form_Parent : Form
    {
        //protected static Database db = new Database();
        protected static DatabaseCopy db = new DatabaseCopy();
        protected static Flockmaster.DBTypes srcType;
        protected static Flockmaster.DBTypes destType;
        protected static DataTable dt = new DataTable();
        protected static IDatabaseCopy Idb;
        protected static List<TableMessage> Messages = new List<TableMessage>();

        public Form_Parent()
        {
            InitializeComponent();
        }
    }
}
